package com.itqf.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @Description:增强类  事务控制  执行监控  日志记录  权限控制
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/9/29
 * @Time: 上午10:56
 */
public class MyAdvice implements MethodBeforeAdvice,AfterReturningAdvice,MethodInterceptor {
    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("前----"+method.getName()+"--"+target.getClass().getSimpleName()+"---"+Arrays.toString(args));
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("前 arround----"+invocation.getMethod());
        //
        Object obj =  invocation.proceed();//调用目标方法

        System.out.println("后 arround----"+invocation.getMethod());

        return obj;
    }

    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("后（afterReturning）----"+method.getName()+"--"+target.getClass().getSimpleName()+"---"+Arrays.toString(args));

    }


}
